package list.test;

import java.io.Serializable;

/**
 * @author PC
 */
public class Student implements Serializable,Cloneable {
    private static final long serialVersionUID = 920046623157153345L;
    /**
    * 姓名
    * */
    private String name;
    /**
     * 年龄
    * */
    private Integer age;

    /**
     * 空参构造
     */
    public Student() {
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    /**
     * @param name 名字
     * @param age 年龄
     */
    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        /*如果进行字符串拼接，会产生很多字符串对象，造成内存浪费
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';*/
        StringBuilder sb = new StringBuilder();
        sb.append("Student{name='");
        //this.name直接到成员变量去找，name会先找局部变量，再找成员变量
        sb.append(this.name);
        sb.append(",age=");
        sb.append(this.age);
        sb.append("}");
        return sb.toString();
    }
}
